package com.example.zhinongbao.activity;
// 联系客服


import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.zhinongbao.R;

public class ContactSupportActivity extends AppCompatActivity {

    private static final String SERVICE_PHONE = "0370-2708088";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact_support);

        // 设置返回按钮功能
        findViewById(R.id.backButton).setOnClickListener(v -> finish());

        // 显示客服电话
        TextView phoneNumber = findViewById(R.id.phoneNumber);
        phoneNumber.setText(SERVICE_PHONE);

        // 设置拨打电话按钮点击事件
        Button callButton = findViewById(R.id.callButton);
        callButton.setOnClickListener(v -> showCallConfirmationDialog());
    }

    private void showCallConfirmationDialog() {
        new AlertDialog.Builder(this)
                .setTitle("温馨提示")
                .setMessage("您确定拨打客服电话：" + SERVICE_PHONE + "？")
                .setNegativeButton("取消", null)
                .setPositiveButton("确定", (dialog, which) -> callService())
                .show();
    }

    private void callService() {
        // 去除电话号码中的连接符
        String phoneNumber = SERVICE_PHONE.replace("-", "");

        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" + phoneNumber));
        startActivity(intent);
    }
}
